
import java.awt.Graphics;
import java.lang.Math;

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author john-skinner
 */
public class Cross  extends GeoDrawable {
    Line l1;
    Line l2;
        @Override
    public boolean pressed(int[] point) {

        Handle sh = handleContains(point);
        if (sh == null) {
            if (m_handles.size() < 4) {
                Handle newHandle = new Handle(point);
                m_handles.add(newHandle);
                return true;

            } else {
                return false;
            }
        } else {
            return super.pressed(point);

        }

    }
        @Override
    public void released(int[] point) {
        super.released(point);

    }

    @Override
    public void drag(int[] point) {
        super.drag(point);

    }
        public void line(Graphics g, int[] v1, int[] v2) {
        int x1 = v1[0];
        int y1 = v1[1];
        int x2 = v2[0];
        int y2 = v2[1];
        g.drawLine(x1, y1, x2, y2);
        int m1 = ((x2+x1)/2); 
        int m2 = ((y2+y1)/2);
      //  g.drawArc(m1-3, m2-3, 6, 6, 0, 180);
     
    }
        @Override
    public void draw(Graphics g) {
        super.draw(g);
        if (m_handles.size() == 4) {
            Handle h1 = m_handles.get(0);
            Handle h2 = m_handles.get(1);
            Handle h3 = m_handles.get(2);
            Handle h4 = m_handles.get(3);
            line(g, h1.m_coord, h2.m_coord);
            line(g, h3.m_coord, h4.m_coord);
         Line l1=new Line(h1.m_coord,h2.m_coord);
         Line l2=new Line(h3.m_coord,h4.m_coord);
         float[]x= l1.intersects(l2);
         float max1 = (l1.m_e1[0]>=l1.m_e2[0])? l1.m_e1[0]:l1.m_e2[0];
         float max2 = (l1.m_e1[1]>=l1.m_e2[1])? l1.m_e1[1]:l1.m_e2[1];
         float min1 = (l1.m_e1[0]<=l1.m_e2[0])? l1.m_e1[0]:l1.m_e2[0];
         float min2 = (l1.m_e1[1]<=l1.m_e2[1])? l1.m_e1[1]:l1.m_e2[1];
         float max3 = (l2.m_e1[0]>=l2.m_e2[0])? l2.m_e1[0]:l2.m_e2[0];
         float max4 = (l2.m_e1[1]>=l2.m_e2[1])? l2.m_e1[1]:l2.m_e2[1];
         float min3 = (l2.m_e1[0]<=l2.m_e2[0])? l2.m_e1[0]:l2.m_e2[0];
         float min4 = (l2.m_e1[1]<=l2.m_e2[1])? l2.m_e1[1]:l2.m_e2[1];

         if(x[0]<=max1&& 
            x[0]>=min1&&
            x[1]<=max2&& 
            x[1]>=min2&&
            x[0]<=max3&& 
            x[0]>=min3&&
            x[1]<=max4&& 
            x[1]>=min4)
             g.drawArc((int)(x[0]) ,(int)(x[1]), 10, 10, 0, 360);

        }
    }
}
